package com.ruoyi.system.service.impl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.entity.SafetyRulesRegulations;
import com.ruoyi.system.mapper.SafetyRulesRegulationsMapper;
import com.ruoyi.system.service.SafetyRulesRegulationsService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 安全承诺卡 服务实现类
 * @since 2023-03-10
 */
@Service("safetyRulesRegulationsService")
public class SafetyRulesRegulationsServiceImpl implements SafetyRulesRegulationsService {

    @Resource
    private SafetyRulesRegulationsMapper safetyRulesRegulationsMapper;

    @Override
    public List<SafetyRulesRegulations> queryByPage(SafetyRulesRegulations safetyRulesRegulations) {
        return safetyRulesRegulationsMapper.queryAllByLimit(safetyRulesRegulations);
    }

    @Override
    public SafetyRulesRegulations queryById(Integer id) {
        return this.safetyRulesRegulationsMapper.queryById(id);
    }

    @Override
    public SafetyRulesRegulations insert(SafetyRulesRegulations safetyRulesRegulations) {
        //safetyRulesRegulations.setCreateUser(SecurityUtils.getUsername());
        this.safetyRulesRegulationsMapper.insert(safetyRulesRegulations);
        return safetyRulesRegulations;
    }

    @Override
    public SafetyRulesRegulations update(SafetyRulesRegulations safetyRulesRegulations) {
        this.safetyRulesRegulationsMapper.update(safetyRulesRegulations);
        return this.queryById(safetyRulesRegulations.getId());
    }

    @Override
    public boolean deleteById(Integer id) {
        return this.safetyRulesRegulationsMapper.deleteById(id) > 0;
    }


    @Override
    public List<SafetyRulesRegulations> selectList(SafetyRulesRegulations safetyRulesRegulations) {
        return safetyRulesRegulationsMapper.queryAll(safetyRulesRegulations);
    }

    @Override
    public String importExcel(List<SafetyRulesRegulations> safetyRulesRegulations, boolean updateSupport, String operName) {
        if (StringUtils.isNull(safetyRulesRegulations) || safetyRulesRegulations.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        safetyRulesRegulationsMapper.insertBatch(safetyRulesRegulations);
        return "成功";
    }

}
